package assets
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.system.ImageDecodingPolicy;
	import flash.system.LoaderContext;
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;
	
	/**
	 * ...
	 * @author Kirill Pletnev
	 */
	public class Assets
	{
		private static const _instance:Assets = new Assets();
		// Texture cache        
		private var _textures:Dictionary = new Dictionary();
		
		public function Assets()
		{
			if (_instance != null)
			{
				throw new Error("TemplateTileManager instance already existing in Singleton");
			}
		}
		
		static public function get instance():Assets
		{
			return _instance;
		}
		
		public function getTexture(name:String):Texture
		{
			if (_textures[name] == undefined)
			{
				var data:Object = new Assets[name]();
				
				if (data is Bitmap)
				{
					_textures[name] = Texture.fromBitmap(data as Bitmap);
				}
				else if (data is ByteArray)
				{
					_textures[name] = Texture.fromAtfData(data as ByteArray);
				}
			}
			
			return _textures[name];
		}
	}
}